<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    <title>商品基本信息维度列表</title>
    <!--{include file="comm/icheck.tpl"}-->
</head>

<style>
	.fbutton .add {background: url("/framework/flexigrid/css/images/add.png") no-repeat scroll left center rgba(0, 0, 0, 0);}
	 
	div .addVal {
		width:90px;
		margin-bottom:2px;
	    background: url("/framework/flexigrid/css/images/bg.gif") repeat-x scroll center top #EAEAEA;
	    border-color: #CCCCCC #CCCCCC -moz-use-text-color;
	    padding:5px;
	    margin-left:10px;
	    cursor:pointer;
	    border-radius:8px;
	}
</style>

<body>

<div class="ebsig_container">
    
    <div class="comm_content">

        <div class="search-box">
            <div style="position:relative">
                <form id="search_form" onsubmit="return false;" class="form-inline">
                	<span>
                    	维度法文：<input type="text" name="french" id="french_search" class="form-control w150" />
                    </span>
                    <span>
                    	维度中文：<input type="text" name="chinese" id="chinese_search" class="form-control w150" />
                    </span>
                    <span>
                    	使用状态：
                        <select  class="form-control w150" id="useFlg_search" name="useFlg">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="0">禁用</option>
                        </select>
                    </span>
                    <span>
                    	<input type="button" value="查询" class="btn btn-primary" onclick="goodsBasic.search();" />
                    </span>
                    <span>
                        <button onclick="goodsBasic.clearUp();" id="clearBtn" class="btn btn-warning" type="button">重置</button>
                    </span>
                </form>
            </div>
        </div>

        <table id="flex" style="display:none"></table>

    </div>

</div>

<div id="pop" style="display: none;">

    <form class="form-horizontal" id="editForm" onsubmit="return false;">

        <div class="form-group">
            <label for="french" class="col-sm-3 control-label"><span class="red">*</span> 维度法文：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control w300" id="french" name="french" />
            </div>
        </div>

        <div class="form-group">
            <label for="chinese" class="col-sm-3 control-label"><span class="red">*</span> 维度中文：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control w300" id="chinese" name="chinese" />
            </div>
        </div>
        
        <div class="form-group">
            <label for="sortOrder" class="col-sm-3 control-label"><span class="red">*</span> 排序：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control w150" id="sortOrder" name="sortOrder" />
            </div>
        </div>

        <button class="btn btn-default" onclick="goodsBasic.specAdd();" type="button">添加基本信息</button>
        <div class="specTable" style="width:694px;">
        	<table class="table table-bordered table-hover">
                <thead>
					<tr>
						<th width="40%" style="text-align:center;">基本信息</th>
						<th width="20%" style="text-align:center;">基本信息值</th>
						<th width="20%" style="text-align:center;">使用标志</th>
						<th width="20%" style="text-align:center;">操作</th>
					</tr>
                </thead>

				<tbody class="specBody"></tbody>
            </table>
        </div>
        <input type="hidden" name="basicGroupID" id="basicGroupID" value="" />

    </form>

</div>

<script type="text/javascript">

$("#flex").flexigrid({
    url:"/invokingAjax-backend/goods/goodsBasic.ajax?operFlg=1",
    dataType: "json",
    colModel : [
            <!--{if isset($edit_permission)}-->    
        	{display: "操作", width : 100, align: "center"},
        	<!--{/if}-->
            {display: "序号", name : "sortOrder", width : 100, sortable : true},
            {display: "维度法文", width : 230 },
            {display: "维度中文",width : 200},
            {display: "维度信息",width : 300},
            {display: "维度信息值",width : 200},
            {display: "使用状态", width : 100 , align: "center"}
        ],
        <!--{if isset($edit_permission)}-->
        buttons : [
            {name: "添加", bclass: "add", width : 200, onpress : "goodsBasic.edit"}
            //{separator: true},
            //{name: "删除", bclass: "delete", onpress : "goodsBasic.del.check"}
        ],
        <!--{/if}-->
        sortname: "sortOrder",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var goodsBasic = {

        i : 0,  //添加基本信息
		useFlg_str : "" ,
		dt:"",
        //搜索规格
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },
        
		doAction: function( basicGroupID , useFlg ) {
            this.basicGroupID = basicGroupID;
            this.useFlg = useFlg;
            if( useFlg == 0 ) {
                E.confirm("您确认要禁用此商品基本信息维度吗？", "goodsBasic.actionConfirm");
            } else {
                E.confirm("您确认要启用此商品基本信息维度吗？", "goodsBasic.actionConfirm");
            }

        },
        
        actionConfirm : function () {

        	E.loadding.open('请稍候...');
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/goodsBasic.ajax?operFlg=6",
                dataType: "JSON",
                data : {
                    basicGroupID: this.basicGroupID,
                    useFlg: this.useFlg
                },
                success: function( result_obj ) {
                	E.loadding.close();
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "goodsBasic.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //编辑或添加弹出框
        edit: function(basicID) {

            E.loadding.open('请稍候...');
            var name="";

            if(basicID){
                name="修改商品基本信息维度";
                E.ajax_post({
                    url: "/invokingAjax-backend/goods/goodsBasic.ajax?operFlg=2",
                    data:{
                        basicGroupID : basicID
                    },
                    call:"goodsBasic.val"
                });

            }else{
                name="添加商品基本信息维度";
                E.ajax_post({
                    url:"/invokingAjax-backend/goods/goodsBasic.ajax?operFlg=3",
                    call:"goodsBasic.sortUp"
                });
            }

            E.popup.open({
                id:"pop",
                title: name,
                css: "width: 760px;margin:-10px auto;overflow:visible;",
                btnName: "保存",
                btnCall:"goodsBasic.check();"
            });
        },


        //编辑弹出层赋值
        val: function(o){
        	E.loadding.close();
            $("#chinese").val(o.chinese);
            $("#french").val(o.french);
            $("#sortOrder").val(o.sortOrder);

            //修改时需要
            $("#basicGroupID").val(o.basicGroupID);
            
            //规格值
            var basicStr = '';
            
            for(var i=0; i<o.goods_basic.length; i++) {
                goodsBasic.i++;

                basicStr += '<tr>';

                basicStr += '<td style="text-align:center;">';
                    basicStr += '<input type="text" maxlength="50"  class="form-control w300" name="basic_val'+goodsBasic.i+'" value="'+o.goods_basic[i]['basicName']+'" style="width:300px;margin:auto;" maxlength="20">';
                basicStr += '</td>';
                
                basicStr += '<td style="text-align:center;">';
	                basicStr += '<input type="text"  maxlength="10" class="form-control w100" name="basicVal'+goodsBasic.i+'" value="'+o.goods_basic[i]['basicVal']+'" style="width:100px;margin:auto;" maxlength="20">';
	            basicStr += '</td>';

                if (o.goods_basic[i]['useFlg'] == 1) {
                    basicStr += '<td style="text-align:center;vertical-align: middle">';
                    basicStr += '<input type="radio" class="square-radio"  name="basic_useFlg'+ goodsBasic.i+'" value="1" checked>启用' +
                                '&nbsp;<input type="radio" class="square-radio"  name="basic_useFlg'+goodsBasic.i+'" value="0">禁用';
                    basicStr += '</td>';
                } else {
                    basicStr += '<td style="text-align:center;vertical-align: middle">';
                    basicStr += '<input type="radio" class="square-radio"  name="basic_useFlg'+goodsBasic.i+'" value="1" >启用' +
                                '&nbsp;<input type="radio" class="square-radio"  name="basic_useFlg'+goodsBasic.i+'" value="0" checked>禁用';
                    basicStr += '</td>';
                }

                basicStr += '<td style="text-align:center;vertical-align: middle" >';
                basicStr += '<img src="/quanliadmin/docroot/images/backend/icon_asc.gif" title="向上移动" style="cursor:pointer;" onclick="goodsBasic.upMove(this);">';
                basicStr += '<img src="/quanliadmin/docroot/images/backend/icon_desc.gif" title="向下移动" style="cursor:pointer;margin-left:12px;" onclick="goodsBasic.downMove(this);">';
                basicStr += '<img src="/quanliadmin/docroot/images/backend/icon_delete.gif" title="删除" value='+o.goods_basic[i]['specID']+' style="cursor:pointer;margin-left:12px;" onclick="goodsBasic.delMove(this);">';
                basicStr += '</td>';

                basicStr += '</tr>';
            }
 
        	$('.specBody').append(basicStr);

            $('.square-radio').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });
        },


        check: function() {
            this.dt = E.getFormValues("editForm");
            var error_msg = "";

            if ($.trim(this.dt.french) == "") {
                error_msg += "维度法文不能为空<br />";
            }

            if ($.trim(this.dt.chinese) == "") {
                error_msg += "维度中文不能为空<br />";
            }

            if (!E.isInt(this.dt.sortOrder)) {
                error_msg += "排序序号必须为数字<br />";
            }

            //使用标志
            var use_array = [];
            //基本信息
            var basic_array = [];
            //基本信息值
            var basicVal = [];
            
            $('[name*=basic_val]').each(function(){
            	var v = E.trim($(this).val());
            	
            	if (v == '') {
            		error_msg += '有未添加的基本信息<br />';
            		return false;
            	}
            });
            
            for(var i=1;i<=goodsBasic.i;i++) {
                if ($.trim($('[name=basic_val'+i+']').val()) != '') {
                    basic_array.push($.trim($('[name=basic_val'+i+']').val()));
                    use_array.push($('[name=basic_useFlg'+i+']:checked').val());
                    basicVal.push($.trim($('[name=basicVal'+i+']').val()));
                }
            }

            if (basic_array.length == 0) {
            	error_msg += "请添加基本信息<br />";
            }
            
            this.basic_array 	= basic_array;
            this.use_array 		= use_array;
            this.basicVal 		= basicVal;

            if (error_msg != "") {
                E.alert(error_msg);
                return false;
            } else {
                goodsBasic.addSave();
            }    
        },

        //保存规格信息
        addSave: function() {
        	
            E.loadding.open("请稍候");
            $basicGroupID = $("#basicGroupID").val();
            
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/goodsBasic.ajax?operFlg=4" ,
                dataType: "JSON",
                data: {
                    basicGroupID: this.dt.basicGroupID,
                    french      : this.dt.french,
                    chinese     : this.dt.chinese,
                    sortOrder   : this.dt.sortOrder,
                    useFlg      : this.dt.useFlg,
                    basic_array : this.basic_array,
                    use_array   : this.use_array,
                    basicVal	: this.basicVal
                },
                success: function( result_obj ) {

                	E.loadding.close();
                    
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "goodsBasic.addload");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        addload : function() {
            window.location.href = 'goodsBasic.pscript?operFlg=1';
        },

        //最大序列号重置
        sortUp:function(o){
        	E.loadding.close();
            $("#sortOrder").val(o.sortOrder);
        },

        load: function() {
            $("#flex").flexReload();
        },
        
        //添加商品基本信息维度信息
        specAdd : function(){

            this.i++;

        	var specStr = '';
        	specStr += '<tr>';

        		specStr += '<td style="text-align:center;">';
        			specStr += '<input maxlength="50" class="form-control w300" type="text" name="basic_val'+goodsBasic.i+'" style="width:300px;margin:auto;" maxlength="20">';
        		specStr += '</td>';
        		
        		specStr += '<td style="text-align:center;">';
	    			specStr += '<input maxlength="10" class="form-control w100" type="text" name="basicVal'+goodsBasic.i+'" style="width:100px;margin:auto;" maxlength="20">';
	    		specStr += '</td>';

                specStr += '<td style="text-align:center;vertical-align: middle;">';
                specStr += '<input type="radio" class="square-radio" class="basicRadio" name="basic_useFlg'+goodsBasic.i+'" value="1" checked>启用' +
                           '&nbsp;<input type="radio" class="square-radio" class="basicRadio" name="basic_useFlg'+goodsBasic.i+'" value="0">禁用';
                specStr += '</td>';

        		specStr += '<td style="text-align:center;vertical-align: middle;" >';
        			specStr += '<img src="/quanliadmin/docroot/images/backend/icon_asc.gif" title="向上移动" style="cursor:pointer;" onclick="goodsBasic.upMove(this);">';
        			specStr += '<img src="/quanliadmin/docroot/images/backend/icon_desc.gif" title="向下移动" style="cursor:pointer;margin-left:12px;" onclick="goodsBasic.downMove(this);">';
        			specStr += '<img src="/quanliadmin/docroot/images/backend/icon_delete.gif" title="删除" style="cursor:pointer;margin-left:12px;" onclick="goodsBasic.delMove(this);">';
        		specStr += '</td>';
        	specStr += '</tr>';
        	
        	$('.specBody').append(specStr);

            $('.square-radio').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });
        },
        
        upMove : function(obj){
        	var objParentTR = $(obj).parent().parent();
			var prevTR = objParentTR.prev();
			if (prevTR.length > 0) {
				prevTR.insertAfter(objParentTR);
			}
        },
        
        downMove : function(obj){
        	var objParentTR = $(obj).parent().parent();
			var nextTR = objParentTR.next();
			if (nextTR.length > 0) {
				nextTR.insertBefore(objParentTR);
			}
        },
        
        delMove : function(obj){

        	//检查当前商品组信息
        	var currentSpec = $(obj).attr('value');
            $(obj).parent().parent().remove();
        },
        
        clearUp: function(){
        	$('#french_search').val('');
        	$('#chinese_search').val('');
        	$('#useFlg_search').val('');
        },

        //删除
        del: {

            p_array: '',

            check: function() {

                var p_obj = $('#flex').find('tr.trSelected');
                if (p_obj.length == 0) {
                    E.alert('请选择要删除的商品基本信息组');
                } else {
                    var temp_array = new Array();
                    $.each(p_obj, function(k, v) {
                        var id = $(v).attr('id').replace('row', '');
                        temp_array.push($(v).attr('id').replace('row', ''));
                    });

                    this.p_array = temp_array;
                    E.confirm('您确认要删除选中的商品基本信息组吗？', 'goodsBasic.del.execute');
                }

            },

            execute: function() {
                E.loadding.open('正在删除商品基本信息组，请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/goods/goodsBasic.ajax?operFlg=5',
                    data: {
                        p_array: this.p_array
                    },
                    call: 'goodsBasic.del.result'
                });
            },

            result: function( o ) {
                E.loadding.close();
                if (o.code == 200) {
                    E.alert('删除成功', 2, 'goodsBasic.load');
                } else {
                    E.alert(o.message);
                }
            }

        }

    };

</script>
</body>
</html>